package com.xxx.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/26  10:35
 * @Copyright
 */
public class RefDome03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("com.xxx.reflect.Student");
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println("method = " + method);
        }

        Method method = aClass.getMethod("show", String.class);
        Constructor<?> constructor = aClass.getDeclaredConstructor(String.class);
        constructor.setAccessible(true);
        Student instance = (Student) constructor.newInstance("张三");

        method.invoke(instance, "张三");

    }
}
